home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 65.zip / BS1 part 65 / Math Visin v2.1 disk 1.adf / Arexx.WB / Simple / AreaBetweenGraphs < prev    next >
Text File  |  1992-02-12  |  3KB  |  109 lines

  1. /* AreaBetweenGraphs   set up MathVision to find area of intersection  14-Nov-89 dh
  2.  
  3.   One common textbook problem is the area between two functions.  This
  4. ARexx program is designed to simplify the setup of this type of problem.
  5.  
  6.   First of all, the two functions are entered in function lines FB and FC.
  7. For example, let us take the two functions "x/2+.5" and cos(x), and find 
  8. the area between them over the interval -3 to 1.  In MathVision enter:
  9.  
  10.   Xmin: -3
  11.   Xmax: 1
  12.   FB:   x/2+.5 ' function 1
  13.   FC:   cos(x) ' function 2
  14.  
  15. Then run this ARexx program.  Watch the comment line as it runs, as it
  16. informs you of what is happening.  It plots both functions on the screen,
  17. and gives you instructions for what to do next.  Note that FA finds the
  18. difference of the two functions.
  19.  
  20.   Use Simple/Analyze to see where the difference is not zero. In this
  21. example, the middle of the screen analyzes to zero, which means we got the 
  22. functions reversed.  Simply edit FA so as to be Max(fc-fb,0).
  23.  
  24.   Then use Area to find the area between the two functions.  The min function
  25. makes it pick up only the area of the intersection, between -2.24 and 0.6.
  26.  
  27. ===========================================================================*/
  28.  
  29. ADDRESS "MathVision"
  30. OPTIONS RESULTS
  31. NUMERIC DIGITS 14
  32.  
  33. EditScreenToFront
  34.       /* see if user has his functions in FB and FC */
  35. get fb
  36. funb = result
  37. get fc
  38. func = result
  39. IF (funb=='RESULT') & (func=='RESULT') THEN DO
  40.   F0 ""
  41.   FB '"Put the formula for the first graph here'
  42.   FC '"Put the formula for the second graph here'
  43.   EXIT
  44. END
  45.  
  46. Comment1 ""
  47. Comment2 ""
  48. Comment3 ""
  49.  
  50.    /* find range of Y which includes both graphs */
  51.  
  52. Comment1 "Finding Range of first function"
  53. F0 "fb"
  54. GuessYminYmax
  55. Get Ymin; YMina = result
  56. Get Ymax; YMaxa = result
  57.  
  58. Comment1 "Finding Range of second function"
  59. F0 "fc"
  60. GuessYminYmax
  61. Get Ymin; YMinb = result
  62. Get Ymax; YMaxb = result
  63.  
  64. miny = min(Ymina, Yminb)
  65. maxy = max(Ymaxa, Ymaxb)
  66.  
  67. Ymin miny      /* plot both graphs now */
  68. Ymax maxy
  69.  
  70. Overplot T
  71. EraseScreen
  72.  
  73. Comment1 "Plotting first function"
  74. PlotScreenToFront
  75. F0 "fb"
  76. SimplePen 1
  77. PlotSimple
  78.  
  79. Comment1 "Plotting second function"
  80. F0 "fc"
  81. SimplePen 2
  82. PlotSimple
  83.  
  84. EditScreenToFront
  85.  
  86. F0 "FA"
  87. Comment1 "Determining which graph is highest"
  88. Get XMin; Minx = RESULT
  89. Get XMax; Maxx = RESULT
  90. FbAbove = 0 /* sample to see which graph is higher the most */
  91. FcAbove = 0
  92. DO i = 0 to 1 by .1
  93.   X MinX+i*(MaxX-MinX)
  94.   Get Eval "fb"
  95.   FbResult = RESULT
  96.   Get Eval "fc"
  97.   FcResult = RESULT
  98.   if (FbResult >= FcResult)
  99.     THEN FbAbove = FbAbove+1
  100.     ELSE FcAbove = FcAbove+1
  101. END
  102. if (FbAbove > FcAbove)
  103.   THEN fa 'max(fb-fc,0) "FB is higher than FC'
  104.   ELSE fa 'max(fc-fb,0) "FC is higher than FB'
  105.  
  106. Comment1 "now use AREA to find the area between the graphs"
  107. Comment2 "Zoom in or out as needed to correctly frame the intersection"
  108. Comment3 "and run the ARexx program again."
  109.